<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: FT
  Date: 2020/9/17
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>用户列表</title>
    <style>
        body{
            background-image: url("/img/background.jpg");
            background-size: 100% 100%;
        }
        div{
            width: 70%;
            margin: 100px auto;
        }
        table{
            margin-left: 10%;
            width: 80%;
            text-align: center;
        }
        .insert{
            margin-left: 10%;
            height: 30px;
            width: 60px;
            margin-bottom: 20px;
        }
        .home{
            margin-left: 2%;
            height: 30px;
            width: 60px;
            margin-bottom: 20px;
        }
        div .page{
            width: 25%;
            height: 50px;
            margin-top: 30px;
        }
        div .page button{
            height: 30px;
            width: 60px;
        }
        .search{
            margin-left: 10%;
        }
    </style>
</head>
<body>
    <div class="box">
        <button class="insert" onclick="location.href='${pageContext.request.contextPath}/add.jsp'">插入</button>
        <button class="home" onclick="location.href='${pageContext.request.contextPath}/index.jsp'">首页</button>
        <%--模糊查询，搜索功能--%>
        <form action="${pageContext.request.contextPath}/user/list" method="post">
            <input class="search" type="text" name="name" placeholder="请输入您要搜索的姓名">
            <input type="submit" value="搜索">
        </form>
        <table border="1" cellspacing="0">
            <th>序列号</th>
            <th>姓名</th>
            <th>年龄</th>
            <th>性别</th>
            <th>工资</th>
            <th>出生日期</th>
            <th>创建时间</th>
            <th>操作</th>
            <c:forEach var="u" items="${page.items}" varStatus="status">
                <tr>
                    <td>${status.count}</td>
                    <td>${u.name}</td>
                    <td>${u.age}</td>
                    <c:if test="${u.sex==1}">
                        <td>男</td>
                    </c:if>
                    <c:if test="${u.sex!=1}">
                        <td>女</td>
                    </c:if>
                    <td>${u.salary}</td>
                    <td>${u.birth}</td>
                    <td>${u.createTime}</td>
                    <td>
                        <a href="${pageContext.request.contextPath}/user/delete?id=${u.id}&currentPage=${page.pageNo}&name=${name}">删除</a>
                        <a href="${pageContext.request.contextPath}/user/toEdit?id=${u.id}">修改</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <%--分页--%>
        <div class="page">
            <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=1&name=${name}'">首页</button>
            <%--上一页--%>
            <c:if test="${page.pageNo==1}">
                <button>上一页</button>
            </c:if>
            <c:if test="${page.pageNo>1}">
                <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=${page.pageNo-1}&name=${name}'">上一页</button>
            </c:if>
            <c:forEach var="pageNum" begin="1" end="${page.pageTotal}">
                <c:if test="${pageNum==page.pageNo}">
                    <a>${pageNum}</a>
                </c:if>
                <c:if test="${pageNum!=page.pageNo}">
                    <a href="${pageContext.request.contextPath}/user/list?currentPage=${pageNum}&name=${name}">${pageNum}</a>
                </c:if>
            </c:forEach>
            <%--下一页--%>
            <c:if test="${page.pageNo==page.pageTotal}">
                <button>下一页</button>
            </c:if>
            <c:if test="${page.pageNo<page.pageTotal}">
                <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=${page.pageNo+1}&name=${name}'">下一页</button>
            </c:if>
            <button onclick="location.href = '${pageContext.request.contextPath}/user/list?currentPage=${page.pageTotal}&name=${name}'">尾页</button>
        </div>
    </div>
</body>
</html>
